<template>
  <!--产品费用信息调整界面-->
  <div style="margin-right:50px;">
    <el-form
      :model="form"
      status-icon
      ref="form"
      label-width="140px"
      class="demo-ruleForm"
      style="margin-top: 50px;"
      size="mini">
      <el-row>
        <el-col :span="8">
          <el-form-item
            label="开始日期:"
            prop="fee_start_date"
            :rules="rules.fee_start_date"
          >
            <el-date-picker
              v-model="form.fee_start_date"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="结束日期:"
            prop="fee_end_date"
            :rules="rules.fee_end_date"
          >
            <el-date-picker
              v-model="form.fee_end_date"
              type="date"
              class="venus-input-middle venus-input-date"
              placeholder="请输入起始日期"
              value-format="yyyyMMdd"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="浮动费用:"
            prop="float_fee"
            :rules="rules.float_fee"
          >
            <el-select
              v-model="form.float_fee"
              placeholder="--请选择--"
              filterable
              clearable
            >
              <el-option
                v-for="value in dict.float_fee_dict"
                :key="value.value"
                :label="value.dtype + '-' + value.text"
                :value="value.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="费用方案:"
            prop="t8_fee_plan_ids"
            :rules="rules.t8_fee_plan_ids"
          >
            <el-select
              v-model="form.t8_fee_plan_ids"
              placeholder="--请选择--"
              filterable
              clearable
              @change="changeFeePlan"
            >
              <el-option
                v-for="value in dict.t8_fee_plan_ids_dict"
                :key="value.value"
                :label="value.code + '-' + value.text"
                :value="value.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item prop="invest_fee_type" label="费用类型">
            <el-checkbox-group v-model="form.invest_fee_type" @change="changeInvestFeeType">
              <el-checkbox v-for="(item,index) in dict.invest_fee_type_option" :key="index" :label="item.itemval" />
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <el-col :xs="0" :sm="0" :md="0">
          <el-input v-model="form.fee_acct_mod" :disabled="true" type="hidden" />
        </el-col>
      </el-row>
      <div style="text-align:center">
        <el-button type="success" @click="domesticcurrency" >提交</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import * as kk from '../../../../../utils/k-utils'
  import request from '../../../../../utils/request'

  export default {
    data() { // 数据定义
      return {
        /* 字典 */
        dict: {
          float_fee_dict: [],
          t8_fee_plan_ids_dict: [],
          invest_fee_type_option: []
        },
        rules: {
          fee_start_date: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          fee_end_date: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          float_fee: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          t8_fee_plan_ids: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          invest_fee_type: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
          fee_acct_mod: [
            { required: true, message: '该项不能为空', trigger: 'blur' }
          ],
        },
        form: {
          fee_start_date: '',
          fee_end_date: '',
          float_fee: '',
          t8_fee_plan_ids: '',
          invest_fee_type: '',
          fee_acct_mod: ''
        }
      }
    },
    mounted() {
      // 初始化调用
      this.init()
    },
    methods: {
      init: function() {
        this.load_dict_exeid(this, 'fee', 'M8loadfees', 'float_fee_dict')
        this.load_dict_exeid(this, 'fee', 'M8loadFeePlans', 't8_fee_plan_ids_dict')
        this.loadData({ type: Number, default: 1 })
      },
      loadData(feeAdType) {
        kk.k_load_exeid('fee', 'M8loadfees', { fee_adtype: feeAdType }).then(resp => {
          if (resp.results > 0) {
            // this.resetFields('updateForm')
            this.dict.invest_fee_type_option = resp.rows
          }
        })
      },
      changeInvestFeeType(params) {
        if (params.length <= 0) {
          this.parmsValue.feePage = []
          return
        }
        // 处理新增
        for (const feeName of params) {
          if (this.parmsValue.feePage.findIndex(page => page.fee_name === feeName) === -1) {
            const feeInfoId = this.parmsValue.update.invest_fee_type_option.find(item => item.itemval === feeName)
            const newFee = { fee_name: feeName, t8_fee_info_id: feeInfoId.itemkey }
            // 初始化共同参数开始
            newFee.billing_number = ''
            newFee.fee_base = ''
            newFee.collect_fee_cycle = ''
            newFee.fee_model = ''
            newFee.rates_value = '0'
            newFee.cost_value = '0'
            newFee.cost_value_down = '0'
            newFee.cost_value_up = '0'
            newFee.firstdate = ''
            // 初始化共同参数结束
            this.parmsValue.feePage.push(newFee)
          }
        }
      },
      /* 通过exeid加载字典 */
      load_dict_exeid(this_object, service_name, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post'
        }).then(rep => {
          this_object['dict'][dict] = rep.rows
        })
      }
    }
  }
</script>
<style scoped>

</style>
